package com.rfid.assistant.base;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;


public class BaseTitleActivity extends AppCompatActivity {

    protected View mBack;
    TextView mTitle;
    ImageView mRightView;
    View mRightViewParent;

    int mRightViewRes;
    View.OnClickListener mRightViewListener;

    @Override
    protected void onStart() {
        super.onStart();
        System.out.println("getTitle() = " + getTitle());
//        mBack = findViewById(R.id.back);
//        mTitle = findViewById(R.id.title);
//        mRightViewParent = findViewById(R.id.right_view_parent);
//        mRightView = findViewById(R.id.right_view);
        if (mRightView != null && mRightViewParent!= null) {
            if (mRightViewListener == null) {
                mRightViewParent.setVisibility(View.GONE);
            } else {
                mRightView.setImageResource(mRightViewRes);
                mRightViewParent.setOnClickListener(mRightViewListener);
            }
        }
        if (mTitle != null) {
            mTitle.setText(getTitle());
        }
        if (mBack != null) {
            mBack.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    finish();
                }
            });
        }
    }

    protected void setRightView(int res, View.OnClickListener listener) {
        mRightViewRes = res;
        mRightViewListener = listener;
        if (mRightView != null) {
            mRightViewParent.setVisibility(View.VISIBLE);
            mRightView.setImageResource(res);
            mRightViewParent.setOnClickListener(listener);
        }
    }

}
